﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Class_KetNoi;

namespace GiaoDien
{
    public partial class uc_LuongNhanVien : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_LuongNhanVien()
        {
            InitializeComponent();
        }
        KetNoi_BangLuong kn = new KetNoi_BangLuong();
        public void LoadDuLieu()
        {
            string sql = "select * from tbl_BangLuong";
            gridControl1.DataSource = kn.taobang(sql);
        }
        public void Nut()
        {
            btnThem.Enabled = false;
            btnSua.Enabled = false;
            btnXoa.Enabled = false;

            btnLuu.Enabled = true;
            btnHuy.Enabled = true;
        }
        private void uc_LuongNhanVien_Load(object sender, EventArgs e)
        {
            kn.connect();
            LoadDuLieu();
            lbMaLuong.Hide();
            txtMaLuong.Hide();
        }
        int flag;
        private void btnThem_Click(object sender, EventArgs e)
        {
            flag = 0;
            Nut();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Nut();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            kn.xoa_BangLuong(txtMaLuong.Text );
            LoadDuLieu();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (flag == 0)
            {
                kn.them_BangLuong(cobThang.Text ,mskNam.Text ,txtMaNV.Text,cobMaPB.Text ,txtLuongCb.Text ,txtNgayTangCa.Text ,txtLuongTangCa.Text ,txtTienBH.Text ,txtThucLanh.Text );
            }
            if (flag == 1)
            {
                kn.sua_BangLuong(txtMaLuong.Text,cobThang.Text, mskNam.Text, txtMaNV.Text, cobMaPB.Text, txtLuongCb.Text, txtNgayTangCa.Text, txtLuongTangCa.Text, txtTienBH.Text, txtThucLanh.Text);
            }
            LoadDuLieu();
            btnThem.Enabled = true;
            btnSua.Enabled =true;
            btnXoa.Enabled =true;

            btnLuu.Enabled = false;
            btnHuy.Enabled = false;
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            txtMaLuong.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaLuong").ToString();
            cobThang.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Thang").ToString();
            mskNam.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Nam").ToString();
            txtMaNV.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaNV").ToString();
            cobMaPB.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaPB").ToString();
            txtLuongCb.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"LuongCB").ToString();
            txtNgayTangCa.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"SoNgayTangCa").ToString();
            txtLuongTangCa.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"LuongTangCa").ToString();
            txtTienBH.Text =gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"TienBaoHiem").ToString();
            txtThucLanh.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ThucLanh").ToString();
        }
    }
}
